﻿using System;
using Kaiser.Models;
using Kaiser.Repositories.iBatis;
using Kaiser.Services;
using Kaiser.Services.Impl;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Kaiser.Test.Modules
{
    [TestClass()]
    [DeploymentItem(@"Kaiser.Site\Maps", "Maps")]
    [DeploymentItem(@"Kaiser.Site\Configs", "Configs")] 
    public class SYSTest
    {
        private ISystemManageService _isystemManageService;

        /// <summary>
        ///GetUserBasicList 的测试
        ///</summary>
        [TestMethod()]
        public void GetUserBasicList()
        {
            try
            {
                IUserService target = new UserService(new SysRepository());
                var search = new UserSearch();
                PagingInfo pageinfo = new PagingInfo();
                //IList<OrderBase> expected = null;
                search.DeptID = "100003";
                DataGrid<UserBasic> actual;
                pageinfo.Size = 10;
                pageinfo.Index = 0;
                pageinfo.SkipTop = 5;
                actual = target.GetList(search, pageinfo);

                //Assert.AreEqual(expected, actual);
                //Assert.Inconclusive("验证此测试方法的正确性。");
            }
            catch (Exception)
            {

                throw;
            }
        }
        [TestMethod()]
        public void InsertOrg()
        {
            try
            {
                for (int i = 0; i < 2; i++)
                {
                    ISystemManageService target = new SystemManageService(new SysRepository());
                    var model = new Org();
                    model.DeptID = Guid.NewGuid().ToString();
                    model.DeptName = "Test00001" + i.ToString();
                    model.DeptCode = "123";
                    model.CreateUserFullName = "0000111";
                    model.CreateDateTime = DateTime.Now;
                    model.CreateUserFullName = "姓名";
                    model.CreateUserName = "username";
                    model.LastUpdateTime = DateTime.Now;
                    model.LastUpdateUserFullName = "姓名1";
                    model.LastUpdateUserName = "姓名1";
                    model.Manager = "条款";
                    model.ParentId = "姓名2";
                    model.Remark = "123213412341231";
                    model.Path = "q1231231";
                    model.Sequence = 12313;

                    target.InsertOrg(model);
                }
            }
            catch (Exception)
            {
                throw;
            }

            Assert.IsFalse(false);
        }

        [TestMethod()]
        public void UpdateOrg()
        {
            try
            {
                ISystemManageService target = new SystemManageService(new SysRepository());
                var model = new Org();
                DataGrid<Org> actual;
                string ParentId = "70a49788-db39-4fc2-88b9-6aeffa1ff63d";
                actual = target.GetSyncOrgTree(ParentId);
                model = actual.rows[0];
                var primaryId = model.DeptID;
                //model = target.GetSyncOrgTree(primaryId);
                model.DeptName = "Test0003";
                target.UpdateOrg(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        [TestMethod()]
        public void GetSyncOrgTree()
        {
            try
            {
                ISystemManageService target = new SystemManageService(new SysRepository());
                DataGrid<Org> actual;
                string ParentId = "70a49788-db39-4fc2-88b9-6aeffa1ff63d";
                actual = target.GetSyncOrgTree(ParentId);
                //Assert.AreEqual(expected, actual);
                Assert.Inconclusive("验证此测试方法的正确性。");
            }
            catch (Exception)
            {

                throw;
            }
        }

        [TestMethod()]
        public void InsertUser()
        {
            try
            {
                for (int i = 0; i < 15; i++)
                {
                    ISystemManageService target = new SystemManageService(new SysRepository());
                    var model = new UserBasic();
                    model.UserName = Guid.NewGuid().ToString();
                    model.FullName = "测试01" + i.ToString();
                    model.UserType = 1; //0,1,2,3,4
                    model.CreateUserFullName = "admin";
                    model.CreateDateTime = DateTime.Now;
                    model.CreateUserName = "admin";
                    model.LastUpdateTime = DateTime.Now;
                    model.LastUpdateUserFullName = "admin";
                    model.LastUpdateUserName = "admin";
                    model.Password = "123456";
                    model.DeptID = "100003";
                    model.Gender = 1;//0,1,9
                    model.Sequence = 12;
                    model.AccountState = 1;//0,1
                    model.Birthday = DateTime.Now;
                    model.Birthplace = "上海市";
                    model.Email = "test@test.com";
                    model.EmailBacker = "test@test.com";
                    model.HomePhone = "1234567";
                    model.IDCard = "123456789012345678";
                    model.MSN = "";
                    model.MobilePhone = "13112341234";
                    model.National = "汉";
                    model.OfficePhone = "2345678";
                    model.QQ = "12345678";
                    model.UserNickName = "administrator";
                    model.UserNO = "admin";
                    target.InsertUser(model);
                }
            }
            catch (Exception)
            {
                throw;
            }

            Assert.IsFalse(false);
        }
        [TestMethod()]
        public void DeleteUser()
        {
            try
            {
                ISystemManageService target = new SystemManageService(new SysRepository()); 
                string UserName = "0caa612c-3cb8-456b-aab1-fd95c2a8b3d1";
                target.DeleteUser(UserName);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }
        [TestMethod()]
        public void UpdateUser()
        {
            try
            {
                ISystemManageService target = new SystemManageService(new SysRepository());
                IUserService teg=new UserService(new SysRepository());
                var model = new UserBasic();
                var username = "6652b68e-7dec-4511-a9ae-90773093266c";
                model = teg.GetItem(username);
                model.UserName = username;
                model.FullName = "测试01";
                target.UpdateUser(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            Assert.Inconclusive("无法验证不返回值的方法。");
        }
    }
}
